package com.bykj.property.config.common.handle;

import com.bykj.property.config.common.exception.CustomException;
import com.bykj.property.controller.vo.response.ErrorCode;
import com.bykj.property.controller.vo.response.RespResult;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException;


/**
* @author yiming

* @description: TODO
* @date 2019/5/20 15:01
*/
@ControllerAdvice
public class CustomExceptionHandler {
private final Logger logger=LoggerFactory.getLogger(CustomExceptionHandler.class);
@ExceptionHandler(value = CustomException.class)
@ResponseBody
public RespResult doCustomException(CustomException e)  {

logger.error("系统异常:{}",e);

return RespResult.error(e.getCode(), e.getMessage());

}
@ExceptionHandler(value = ValidationException.class)
@ResponseBody
public RespResult doViolationException(ValidationException e)  {

logger.error("系统异常:{[]}",e);

return RespResult.error(ErrorCode.VALI.getCode(), e.getMessage());

}
    @ExceptionHandler(value = IncorrectCredentialsException.class)
    @ResponseBody
    public RespResult doIncorrectCredentials(IncorrectCredentialsException e)  {

        logger.error("系统异常:{[]}",e);

        return RespResult.error(ErrorCode.LOGIN_VAIL_FAIL);

    }

@ExceptionHandler(value = Exception.class)
@ResponseBody
public RespResult doHandler(Exception e) {

logger.error("系统异常:{[]}",e);
return RespResult.error(ErrorCode.SYS_ERR);

}
}
